#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_sumBtn_clicked()
{
    QString count = ui->countText->text();
    QString place = ui->placeText->text();
    float num = count.toFloat();
    float p = place.toFloat();
    ui->sumText->setText(QString::number((num*p), 'f', 2));
}


void Widget::on_bitBtn_clicked()
{
    bool ok;
    int bit = ui->bitText->text().toInt(&ok, 2);
    ui->decText->setText(QString::number(bit));
    ui->hexText->setText(QString::number(bit, 16).toUpper());
}


void Widget::on_decBtn_clicked()
{
    int dec = ui->decText->text().toInt();
    ui->bitText->setText(QString::number(dec, 2));
    ui->hexText->setText(QString::number(dec, 16).toUpper());
}


void Widget::on_hexBtn_clicked()
{
    bool ok;
    int hex = ui->hexText->text().toInt(&ok, 16);
    ui->bitText->setText(QString::number(hex, 2));
    ui->decText->setText(QString::number(hex));
}

